<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48" v-show="projectShowType !== '1'">
          <a-col :span="12" :hidden="true">
            <a-form-model-item label="流程名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle">
              <a-input
                :max-length="255"
                :disabled="formDisabled"
                v-model="model.bpmBizTitle"
                placeholder="请输入流程名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="档案编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectNo">
              <a-input :disabled="isDisableProjectNo" v-model="model.finalNo" placeholder="请输入档案编号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date
                placeholder="请选择申请时间"
                v-model="model.createTime"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm"
                style="width: 100%"
                disabled />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createBy">
              <!--              <select-user-by-dep :disabled=formDisabled v-model="model.proposer" disabled/>-->
              <!-- <select-user-by-dep :disabled="formDisabled" :multi="false" v-model="model.proposer" disabled /> -->
              <j-select-user-by-dep v-model="model.createBy" :multi="false" disabled></j-select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sysOrgCode">
              <!-- <j-select-depart :disabled="formDisabled" v-model="model.proposerDeptId" multi disabled/> -->
              <j-select-depart
                v-model="model.sysOrgCode"
                :trigger-change="true"
                disabled
                customReturnField="orgCode"
                :multi="true"></j-select-depart>
            </a-form-model-item>
          </a-col>
          <a-divider>基本信息</a-divider>
          <a-col :span="12">
            <a-form-model-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPrepareEstablish">
              <!-- <j-dict-select-tag :disabled=formDisabled @input="isPrepareEstablishChange" type="radio"
                                v-model="model.isPrepareEstablish" dictCode="YES_OR_NO"
                                placeholder="请输入是否预立项"></j-dict-select-tag> -->
              <!-- <j-dict-select-tag :disabled=formDisabled type="list"  :key="5" @input="handleInput" v-model="model.isPrepareEstablish" dictCode="omc_project_type" placeholder="请选择数据来源" /> -->
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                @input="isPrepareEstablishChange"
                v-model="model.isPrepareEstablish"
                dictCode="omc_project_type"
                placeholder="请选择数据来源" />
            </a-form-model-item>
          </a-col>

          <!--          <a-col :span="12" v-if="model.isPrepareEstablish == '0'" >-->
          <!--            &lt;!&ndash; <a-col :span="12" v-if="isShowPrepareProject" > &ndash;&gt;-->
          <!--            <a-form-model-item label="预立项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="finalProjectId">-->
          <!--              <select-project-input-->
          <!--                :proDisabled="proDisabled"-->
          <!--                :projectStatus="'1'"-->
          <!--                :disabled="formDisabled"-->
          <!--                v-model="model.finalProjectId"-->
          <!--                :changeStatus = "'unchanged'"-->
          <!--                @back="prepareProjectChange"/>-->
          <!--              &lt;!&ndash;              <a-input v-if="!isShowPrepareProject"  v-model="model.projectName" placeholder="请输入项目名称"></a-input>&ndash;&gt;-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->

          <!-- <a-col :span="12" v-if="isShowPrepareProject" > -->
          <a-col :span="12" v-if="model.isPrepareEstablish == '1'">
            <a-form-model-item label="投标档案" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderFinalCode">
              <!-- <SelectOmcTenderFileInput
                :proDisabled="proDisabled"
                :projectStatus="'1'"
                :disabled="formDisabled"
                v-model="model.finalProjectId"
                :changeStatus = "'unchanged'"
                @back="prepareProjectChange"/> -->
              <!-- <j-popup
                :disabled=formDisabled
                v-model="model.tenderFinalCode"
                field="tenderFinalId"
                placeholder="请选择投标编号"
                dest-fields="tenderFinalId,prepareProjectId,id"
                org-fields ="final_no,prepare_project_id,id"
                code="erp_omc_tender_final_model"
                @input="popupCallback"
              /> -->
              <select-omc-project-tender-input :disabled="formDisabled" v-model="model.tenderFinalCode" />
            </a-form-model-item>
            <!--              <a-input v-if="!isShowPrepareProject"  v-model="model.projectName" placeholder="请输入项目名称"></a-input>-->

          </a-col>

          <!-- <a-col :span="12" v-if="!isShowPrepareProject" > -->
          <!-- <a-col :span="12" v-if="isShowPrepareProject" > -->
          <template>
            <a-col :span="12">
              <a-form-model-item label="项目档案状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentProjectStatus">
                <j-dict-select-tag
                  :disabled="formDisabled"
                  type="list"
                  v-model="model.currentProjectStatus"
                  dictCode="current_project_status"
                  placeholder="请选择项目档案状态"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="12" v-if="model.currentProjectStatus == '2'">
              <a-form-model-item label="终止时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectEndDate">
                <j-date :disabled="formDisabled" placeholder="请选择终止时间" v-model="model.projectEndDate" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
          </template>
          <a-col :span="12">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName">
              <a-input :disabled="formDisabled" v-model="model.projectName" placeholder="请输入项目名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="经营团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nowTeamName">
              <!--              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.nowTeamName" dictCode="teams" placeholder="请选择经营团队" />-->
              <select-team-input :disabled="formDisabled" v-model="model.nowTeamName" :tdlx="1" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12"> -->
          <!-- <a-form-model-item label="经营公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessCompanyId">
              <select-Company-input :disabled="formDisabled" placeholder="请选择经营公司" v-model="model.signUnit" disabled />
            </a-form-model-item> -->
          <!-- <a-form-model-item label="经营公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessCompanyId">
              <select-Company-input :disabled="formDisabled" placeholder="请选择经营公司" v-model="model.businessCompanyId" disabled />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12">
            <a-form-model-item label="项目承接人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="undertaker">
              <!--              <select-user-by-dep :disabled=formDisabled v-model="model.undertaker"/>-->
              <select-user-by-dep :disabled="formDisabled" :multi="false" v-model="model.undertaker" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="立项日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectEstablishDate">
              <j-date
                :disabled="formDisabled"
                placeholder="请选择立项日期"
                v-model="model.projectEstablishDate"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="是否投标、报价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfztb">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="radio"
                v-model="model.isBidding"
                dictCode="yn"
                placeholder="请选择是否投标、报价"/>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12">
            <a-form-model-item label="签订单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signUnit">
              <!--              <j-select-company :disabled=formDisabled placeholder="请选择签订单位" v-model="model.signUnit"/>-->
              <select-Company-input :disabled="formDisabled" placeholder="请选择签订单位" v-model="model.signUnit" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="业绩归属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.year"
                dictCode="yjgsnd"
                placeholder="请选择归属年度" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="是否环评项目"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="isEnvironmentalAssessmentProject">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="radio"
                v-model="model.isEnvironmentalAssessmentProject"
                dictCode="YES_OR_NO"
                placeholder="请选择是否环评项目" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="业主单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerUnit">
              <!--              <a-input :disabled=formDisabled v-model="model.ownerUnit" placeholder="请输入业主单位"  ></a-input>-->
              <select-customer-input
                :disabled="formDisabled"
                v-model="model.ownerUnit"
                commercialType="1"
                @change="ownerUnitChange" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contacts">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.contacts"
                :dictCode="customer_contacts"
                placeholder="请选择联系人"
                @change="contactsChange"
                :triggerChange="true" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactTel">
              <a-input :disabled="formDisabled" v-model="model.contactTel" placeholder="请输入联系方式"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="业主角色" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerRole">
              <j-dict-select-tag
                :disabled="formDisabled"
                v-model="model.ownerRole"
                dictCode="owner_role"
                placeholder="请选择业主角色"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="企业类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enterpriseType">
              <j-dict-select-tag disabled type="list" v-model="model.enterpriseType" dictCode="enterprise_type" placeholder="请选择企业类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="项目所在地址"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              style="height:75px"
              prop="projectAddress">
              <a-form-model-item :style="{display:'inline-block',width:'48%'}" prop="projectAddress">
                <AddressChoice :disabled="formDisabled" type="cascader" v-model="model.areaCode" placeholder="请输入省市区" />
              </a-form-model-item>
              <a-form-model-item
                :style="{'margin-top':'0px','margin-left':'5px',display:'inline-block',width:'50%'}"
                prop="projectAddress">
                <a-input :disabled="formDisabled" v-model="model.projectAddress" placeholder="请输入项目详细地址"></a-input>
              </a-form-model-item>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectSource">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.projectSource"
                dictCode="xmly_type"
                placeholder="请选择项目来源" />
            </a-form-model-item>
          </a-col>
          <!--          <a-col :span="12">-->
          <!--            <a-form-model-item label="台账管理员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountAdmin">-->
          <!--              <select-user-by-dep-->
          <!--                  :disabled=formDisabled-->
          <!--                  v-model="model.accountAdmin"/>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col :span="12">
            <a-form-model-item
              label="预计合同额（元）"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="estimatedContractAmount">
              <a-input-number
                :disabled="formDisabled"
                :max="99999999"
                :min="0"
                :precision="2"
                v-model="model.estimatedContractAmount"
                placeholder="请输入预计合同额"
                style="width: 100%"
                @blur="convertMoney" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="预计合同额大写"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="estimatedContractcapitalChineseAmount">
              <a-input
                :disabled="formDisabled"
                v-model="model.estimatedContractcapitalChineseAmount"
                placeholder="请输入预计合同额大写"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="经营绩效(元)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="businessPerformance">
              <a-input-number
                :disabled="formDisabled"
                :max="99999999"
                :min="0"
                :precision="2"
                v-model="model.businessPerformance"
                placeholder="请输入经营绩效"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12" v-if="isDetail">
            <a-form-model-item label="分配方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="distributionMethod">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.distributionMethod"
                dictCode="distribution_method"
                placeholder="请选择分配方式" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12" v-if="isDetail">
            <a-form-model-item label="项目变更状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changeStatus">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.changeStatus"
                dictCode="change_status"
                placeholder="请选择项目变更状态"
                @change="htlxChange"
                :triggerChange="true" />
            </a-form-model-item>
          </a-col>
          <!--          <a-col :span="12">-->
          <!--            <a-form-model-item label="项目内容概要" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outline">-->
          <!--              <a-textarea :disabled=formDisabled v-model="model.outline" rows="4" placeholder="请输入项目内容概要"/>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="立项事由及说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="establishReason">
              <a-textarea
                :disabled="formDisabled"
                :max-length="500"
                v-model="model.establishReason"
                rows="4"
                placeholder="请输入立项事由及说明" />
            </a-form-model-item>
          </a-col>
            <a-col :span="24">
            <a-form-model-item label="相关附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachment">
              <j-upload :disabled="formDisabled" if="!formDisabled" v-model="model.attachment"></j-upload>
            </a-form-model-item>
          </a-col>
           
          <a-col :span="12">
          <a-form-model-item
              label="分配方式"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="distributionMethod">

                <j-dict-select-tag
                  :disabled="formDisabled"
                  type="list"
                  v-model="model.distributionMethod"
                  dictCode="distribution_method"
                  placeholder="请选择分配方式" @change="getForMoney()"/>

            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="主生产团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mainProductionTeam">
              <select-team-input
                :disabled="true"
                v-model="model.mainProductionTeam"
                :teamType="0"
                :tdlx="2"/>
            </a-form-model-item>
          </a-col>

          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
          <a-col :span="24">
            <!--          <div style="margin-bottom: 6px;margin-top: 6px">-->
            <!--            <a-button @click="handleAdd" v-if="!formDisabled" type="primary">新增</a-button>-->
            <!--          </div>-->
            <a-table
              ref="table"
              size="middle"
              rowKey="id"
              bordered
              :scroll="{x:scrollX}"
              :components="draggableComponent"
              :loading="loading"
              :columns="columns"
              :pagination="false"
              :data-source="dataSource">
              <span slot="action" slot-scope="text, record">
                <template v-if="!formDisabled">
                  <a-button class="ruleButton" :ghost="true" type="primary" icon="edit" @click="handleEdit(record)" />
                  <a-divider type="vertical" />
                  <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                    <a-button class="ruleButton" :ghost="true" type="primary" icon="delete" />
                  </a-popconfirm>
                </template>
                <template v-if="isDetailButton && record.billNo">
                  <a @click="handleDetail(record)">详情</a>
                </template>
              </span>
            </a-table>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24" v-if="progressShowType !== '2'">
            <a-tabs @change="handleChangeTab">
              <a-tab-pane tab="任务进度" :forceRender="true" key="1">
                <a-row :gutter="24">
                  <a-col :span="24">
                    <a-table
                      ref="table"
                      rowKey="id"
                      size="middle"
                      bordered
                      :scroll="{ x: scrollXOther }"
                      :components="draggableComponentOther"
                      :pagination="false"
                      :columns="taskProgressColumns"
                      :dataSource="dataSource3"
                      :loading="loading">
                      <template slot="status" slot-scope="status">
                        <a-badge :status="status | statusTypeFilter" :text="status | statusFilter" />
                      </template>
                      <template slot="htmlSlot" slot-scope="text">
                        <div v-html="text"></div>
                      </template>
                      <template slot="imgSlot" slot-scope="text">
                        <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                        <img
                          v-else
                          :src="getImgView(text)"
                          height="25px"
                          alt=""
                          style="max-width:80px;font-size: 12px;font-style: italic;" />
                      </template>
                      <template slot="fileSlot" slot-scope="text">
                        <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                        <a-button
                          v-else
                          :ghost="true"
                          type="primary"
                          icon="download"
                          size="small"
                          @click="downloadFile(text)">
                          下载
                        </a-button>
                      </template>
                      <a slot="projectNo" slot-scope="text, record" @click="handleViews(record.projectId)">{{ text
                      }}</a>
                    </a-table>
                  </a-col>
                </a-row>
              </a-tab-pane>
            </a-tabs>
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :col="24">
            <a-tabs>
              <a-tab-pane tab="申请记录" :forceRender="true" key="1">
                <a-tabs @change="changeProjectTab">
                  <a-tab-pane tab="预立项" :forceRender="true" key="1">
                    <a-row :gutter="24">
                      <a-col :span="24">
                        <a-table
                          ref="table"
                          rowKey="id"
                          size="middle"
                          bordered
                          :pagination="false"
                          :columns="prepareProjectColumns"
                          :scroll="{ x: scrollXThree }"
                          :components="draggableComponentThree"
                          :dataSource="prepareProjectApplyDataSource"
                          :loading="prepareProjectApplyLoading">
                          <template slot="status" slot-scope="status">
                            <a-badge :status="status | statusTypeFilter" :text="status | statusFilter" />
                          </template>
                          <template slot="htmlSlot" slot-scope="text">
                            <div v-html="text"></div>
                          </template>
                          <template slot="imgSlot" slot-scope="text">
                            <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                            <img
                              v-else
                              :src="getImgView(text)"
                              height="25px"
                              alt=""
                              style="max-width:80px;font-size: 12px;font-style: italic;" />
                          </template>
                          <template slot="fileSlot" slot-scope="text">
                            <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                            <a-button
                              v-else
                              :ghost="true"
                              type="primary"
                              icon="download"
                              size="small"
                              @click="downloadFile(text)">
                              下载
                            </a-button>
                          </template>
                          <span slot="action" slot-scope="text, record">
                            <template>
                              <a @click="handlePrepareProjectDetail(record)">详情</a>
                            </template>
                          </span>
                        </a-table>
                      </a-col>
                    </a-row>
                  </a-tab-pane>
                  <a-tab-pane tab="立项/立项变更" :forceRender="true" key="2">
                    <a-row :gutter="24">
                      <a-col :span="24">
                        <a-table
                          ref="table"
                          rowKey="id"
                          size="middle"
                          bordered
                          :pagination="false"
                          :columns="projectApplyColumns"
                          :scroll="{ x: scrollXThree }"
                          :components="draggableComponentThree"
                          :dataSource="projectApplyDataSource"
                          :loading="projectApplyLoading">
                          <template slot="status" slot-scope="status">
                            <a-badge :status="status | statusTypeFilter" :text="status | statusFilter" />
                          </template>
                          <template slot="htmlSlot" slot-scope="text">
                            <div v-html="text"></div>
                          </template>
                          <template slot="imgSlot" slot-scope="text">
                            <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                            <img
                              v-else
                              :src="getImgView(text)"
                              height="25px"
                              alt=""
                              style="max-width:80px;font-size: 12px;font-style: italic;" />
                          </template>
                          <template slot="fileSlot" slot-scope="text">
                            <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                            <a-button
                              v-else
                              :ghost="true"
                              type="primary"
                              icon="download"
                              size="small"
                              @click="downloadFile(text)">
                              下载
                            </a-button>
                          </template>
                          <span slot="action" slot-scope="text, record">
                            <template>
                              <a @click="handleProjectDetail(record)">详情</a>
                            </template>
                          </span>
                        </a-table>
                      </a-col>
                    </a-row>
                  </a-tab-pane>
                </a-tabs>
              </a-tab-pane>
            </a-tabs>
          </a-col>
        </a-row>
      </a-form-model>
      <view-file-modal ref="viewFileModal"></view-file-modal>
      <erp-my-omc-project-task-modal ref="categoryList" @ok="modalFormOk"></erp-my-omc-project-task-modal>
      <erp-progress-contract-views-modal ref="viewsModalForm" @ok="modalFormOk"></erp-progress-contract-views-modal>
      <erp-progress-payment-views-modal ref="paymentView" @ok="modalFormOk"></erp-progress-payment-views-modal>
      <ErpTaskReportModal ref="taskReportForm"></ErpTaskReportModal>
      <ErpApplyProjectReportModal ref="projectReportForm"></ErpApplyProjectReportModal>
      <ErpApplyPrepareProjectReportModal ref="prepareProjectReportForm"></ErpApplyPrepareProjectReportModal>
      <!-- <erp-my-omc-project-task-list :allow-change="allowChange"
                                              ref="categoryList"></erp-my-omc-project-task-list> -->
    </j-form-container>
  </a-spin>
</template>

<script>

import { getAction, httpAction } from '@/api/manage'
import { viewFile } from '@/utils/util'
import ViewFileModal from '@/views/scy/components/ViewFileModal'
import SelectTeamInput from '@views/scy/components/SelectTeamInput';
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectCustomerInput from '@views/scy/components/SelectCustomerInput';
import { convertCurrency } from '@/utils/MoneyConvert';
import ErpMyOmcProjectTaskModal from '@views/erp/omc/project/modules/reference/ErpMyOmcProjectTaskModal';
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
import { mapGetters } from 'vuex';
import moment from 'moment';
import AddressChoice from '@/components/AddressChoice/AddressChoice';
import ErpProgressContractViewsModal from '@views/erp/progress/modules/ErpProgressContractViewsModal';
import ErpProgressPaymentViewsModal from '@views/erp/progress/modules/ErpProgressPaymentViewsModal';
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import Ellipsis from '@/components/Ellipsis'
import SelectOmcProjectTenderInput from '@/views/scy/components/SelectOmcProjectTenderInput';
import ErpTaskReportModal from '@views/erp/omc/taskdistribution/modules/ErpTaskReportModal.vue'; // 任务档案详情
import ErpApplyProjectReportModal from './reference/ErpApplyProjectReportModal.vue'; // 立项详情
import ErpApplyPrepareProjectReportModal from './reference/ErpApplyPrepareProjectReportModal.vue'; // 预立项详情
import { DragResizable } from '@/mixins/DragResizable'
import { modes } from 'codemirror';
export default {
  name: 'ErpOmcProjectForm',
  mixins: [viewFile, DragResizable],
  components: {
    SelectOmcProjectTenderInput,
    Ellipsis,
    ErpMyOmcProjectTaskModal,
    SelectTeamInput,
    SelectUserByDep,
    SelectCustomerInput,
    ViewFileModal,
    AddressChoice,
    ErpProgressContractViewsModal,
    ErpProgressPaymentViewsModal,
    SelectCompanyInput,
    ErpTaskReportModal,
    ErpApplyProjectReportModal,
    ErpApplyPrepareProjectReportModal
  },
  watch: {
    projectId: {
      handler (val) {
        this.$route.params.id = val
        this.loadDataByProjectId(val)
      },
      immediate: true
    },
    $route(to, from) {

    }
  },
  props: {
    isDetail: {
      type: Boolean,
      default: true
    },
    isDetailButton: {
      type: Boolean,
      default: false
    },
    allowChange: {
      type: Boolean,
      default: false,
      required: false
    },
    // 流程表单data
    formData: {
      type: Object,
      default: () => {
      },
      required: false
    },
    // 表单模式：true流程表单 false普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false
    },
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    // 控制项目信息显示
    projectId: {
      type: String,
      default: '',
      required: false
    },
    // 控制项目信息显示
    projectShowType: {
      type: String,
      default: '-1',
      required: false
    },
    // 控制进度信息显示
    progressShowType: {
      type: String,
      default: '-2',
      required: false
    }
  },
  data() {
    return {
      taskShowType: false,
      projectIdTo: null,
      isShowPrepareProject: false,
      isDisableProjectNo: false,
      formTitle: '',
      current: 0,
      nodeList: [],
      modelTask: {},
      model: {
        isEnvironmentalAssessmentProject: '0',
        isPrepareEstablish: '0',
        isBidding: '0'
      },
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      confirmLoading: false,
      validatorRules: {
        prepareProjectId: [
          { required: true, message: '请输入预立项!' }
        ],
        projectId: [
          { required: true, message: '请输入已立项项目!' }
        ],
        projectNo: [
          { required: true, message: '请输入已立项项目编号!' }
          // { validator: (rule, value, callback) => validateDuplicateValue('erp_omc_project', 'project_no', value, this.model.id, callback)},
        ],
        estimatedContractAmount: [
          { required: false },
          { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        contactTel: [
          { required: false },
          { pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系方式!' }
        ]
      },
      url: {
        ProgressTaskList: '/api/erp/progress/erpProgressTask/progressList',
        add: '/api/erp/omc/project/erpOmcProjectApply/add',
        edit: '/api/erp/omc/project/erpOmcProjectApply/editProject',
        queryById: '/api/erp/omc/project/erpOmcProjectApply/queryById',
        queryPrepareProjectById: '/api/erp/omc/prepareproject/erpOmcPrepareProject/queryById',
        queryProjectById: '/api/erp/omc/project/erpOmcProject/queryById',
        getProjectNo: '/api/erp/omc/project/erpOmcProjectApply/getProjectNo',
        queryTaskTreeById: '/api/erp/progress/erpProgressTask/queryTaskTreeById',
        proQueryById: '/api/erp/omc/project/erpOmcProjectTask/queryById',
        queryTaskNodeInfoById: '/api/erp/progress/erpProgressTaskNode/queryTaskNodeInfoById',
        queryListByProjectId: '/api/erp/progress/erpProgressContractNode/queryListByContractId',
        PaymentNodeByProjectId: '/api/erp/progress/erpProgressPaymentNode/queryListByProjectId',
        queryListByTaskByIds: '/api/erp/progress/erpProgressTaskNode/queryListByTaskByIds',
        taskById: '/api/erp/omc/project/erpOmcProjectTaskFinal/queryPageList'
      },
      // customer_contacts: 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=0',
      customer_contacts: 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 ',
      loading: false,
      prepareProjectApplyLoading: false, // 申请记录loading
      projectApplyLoading: false, // 申请记录loading
      dataSource: [],
      dictOptions: {},
      // 任务进度列表
      taskProgressColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        // {
        //   title: '进度编码',
        //   align: 'center',
        //   dataIndex: 'billNo',
        //   ellipsis: true,
        //   scopedSlots: { customRender: 'billNo' }
        // },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
          width: 120,
          ellipsis: true
        },
        {
          title: '任务编码',
          align: 'center',
          dataIndex: 'taskBillNo',
          width: 120,
          ellipsis: true
        },
        {
          title: '业务分类',
          align: 'center',
          dataIndex: 'categoryName',
          width: 120,
          ellipsis: true
        },
        {
          title: '匹配合同额(元)',
          align: 'center',
          dataIndex: 'newContractAmount',
          width: 120,
          ellipsis: true
        },
        {
          title: '生产团队',
          align: 'center',
          dataIndex: 'productTeam_dictText',
          width: 120,
          ellipsis: true
        },
        {
          title: '实施部门',
          align: 'center',
          dataIndex: 'executeDepart_dictText',
          width: 120,
          ellipsis: true
        },
        {
          title: '部门负责人',
          align: 'center',
          dataIndex: 'minister_dictText',
          width: 120,
          ellipsis: true
        },
        {
          title: '项目负责人',
          align: 'center',
          dataIndex: 'projLeadName',
          width: 120,
          ellipsis: true
        },
        {
          title: '任务进度',
          align: 'center',
          dataIndex: 'taskProgress',
          width: 120,
          ellipsis: true
        },
        // {
        //   title: '指派时间',
        //   align: 'center',
        //   dataIndex: 'createTime',
        //   ellipsis: true
        // },
        {
          title: '进度百分比(%)',
          align: 'center',
          dataIndex: 'contractRate',
          width: 120,
          ellipsis: true
        },
        {
          title: '已完成进度',
          align: 'center',
          dataIndex: '',
          width: 120,
          ellipsis: true
        }, {
          title: '项目预算',
          align: 'center',
          dataIndex: 'totalProjectBudget',
          width: 120,
          ellipsis: true
        }, {
          title: '预算工时',
          align: 'center',
          dataIndex: 'expectWorkTime',
          width: 120,
          ellipsis: true
        }, {
          title: '确认收入',
          align: 'center',
          dataIndex: '',
          width: 120,
          ellipsis: true
        }, {
          title: '完成时间',
          align: 'center',
          dataIndex: 'completeTime',
          width: 120,
          ellipsis: true
        }, {
          title: '是否变更中',
          align: 'center',
          dataIndex: 'changeStatus_dictText',
          width: 120,
          ellipsis: true
        }, {
          title: '是否存档',
          align: 'center',
          dataIndex: 'isInFile_dictText',
          width: 120,
          ellipsis: true
        },
        // {
        //   title: '预计总工时(人/天)',
        //   align: 'center',
        //   dataIndex: 'expectTotalHours',
        //   ellipsis: true
        // },
        // {
        //   title: '已消耗总工时(人/天)',
        //   align: 'center',
        //   dataIndex: 'consumedHours',
        //   ellipsis: true
        // },
        {
          title: '任务状态',
          align: 'center',
          dataIndex: 'taskStatus_dictText',
          width: 120,
          ellipsis: true
        }
      ],
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '任务档案编号',
          align: 'center',
          dataIndex: 'billNo',
          width: 176,
          ellipsis: true
        },
        {
          title: '业务分类编码',
          align: 'center',
          dataIndex: 'categoryCode',
          width: 176,
          ellipsis: true
        },
        {
          title: '业务分类名称',
          align: 'center',
          dataIndex: 'categoryName',
          width: 176,
          ellipsis: true
        },
        {
          title: '合同占比（%）',
          align: 'center',
          dataIndex: 'contractRate',
          width: 176,
          ellipsis: true
        },
        {
          title: '分配合同额（元）',
          align: 'center',
          dataIndex: 'contractAmount',
          width: 176,
          ellipsis: true
        },
        {
          title: '切割合同额（元）',
          align: 'center',
          dataIndex: 'cutContractAmount',
          width: 176,
          ellipsis: true
        },
        {
          title: '生产团队',
          align: 'center',
          dataIndex: 'productTeam',
          width: 176,
          ellipsis: true,
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['productTeam'], text + '')
            }
          }
        },
        {
          title: '团队负责人',
          align: 'center',
          dataIndex: 'teamLeader',
          width: 176,
          ellipsis: true,
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['teamLeader'], text + '')
            }
          }
        },
        {
          title: '任务说明',
          align: 'center',
          ellipsis: true,
          width: 176,
          dataIndex: 'taskDescription'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 150,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      columnsdata: [
        {
          title: '收款单编号',
          align: 'center',
          dataIndex: 'categoryCode',
          ellipsis: true
        },
        {
          title: '汇款单位',
          align: 'center',
          dataIndex: 'categoryName',
          ellipsis: true
        },
        {
          title: '汇款日期',
          align: 'center',
          dataIndex: 'contractRate',
          ellipsis: true
        },
        {
          title: '汇款单位',
          align: 'center',
          dataIndex: 'contractAmount',
          ellipsis: true
        },
        {
          title: '收款账户',
          align: 'center',
          ellipsis: true,
          dataIndex: 'productTeam'
        },
        {
          title: '汇款金额（元）',
          align: 'center',
          dataIndex: 'teamLeader'
        }
      ],
      // 申请记录
      // 预立项列表
      prepareProjectColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          ellipsis: true,
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'billNo',
          ellipsis: true,
          width: 124
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'mc',
          ellipsis: true,
          width: 124
        },
        {
          title: '经营团队',
          align: 'center',
          dataIndex: 'ywtd_dictText',
          ellipsis: true,
          width: 124
        },
        {
          title: '项目承接人',
          align: 'center',
          dataIndex: 'cjr_dictText',
          ellipsis: true,
          width: 124
        },
        {
          title: '签订单位',
          align: 'center',
          dataIndex: 'qddw_dictText',
          ellipsis: true,
          width: 124
        },
        {
          title: '业主单位',
          align: 'center',
          dataIndex: 'yzdw_dictText',
          ellipsis: true,
          width: 124
        },
        {
          title: '预计合同额(元)',
          align: 'center',
          dataIndex: 'yjhte',
          ellipsis: true,
          width: 124
        },
        {
          title: '项目来源',
          align: 'center',
          dataIndex: 'xmly_dictText',
          ellipsis: true,
          width: 124
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'proposer_dictText',
          ellipsis: true,
          width: 124
        },
        {
          title: '申请部门',
          align: 'center',
          dataIndex: 'proposerDeptId_dictText',
          ellipsis: true,
          width: 124
        },
        {
          title: '流程状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          ellipsis: true,
          width: 124
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      // 立项列表
      projectApplyColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          // fixed: 'left',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'projectNo',
          ellipsis: true,
          width: 153
          // fixed: 'left',
          // width: 60,
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
          // fixed: 'left',
          // width: 60,
          ellipsis: true,
          width: 153
        },
        {
          title: '申请类型',
          align: 'center',
          // width:60,
          dataIndex: 'applyType_dictText',
          ellipsis: true,
          width: 153
        },
        {
          title: '经营团队',
          align: 'center',
          dataIndex: 'teamName_dictText',
          ellipsis: true,
          width: 153
        },
        {
          title: '项目承接人',
          align: 'center',
          dataIndex: 'undertaker_dictText',
          ellipsis: true,
          width: 153
        },
        {
          title: '签订单位',
          align: 'center',
          dataIndex: 'signUnit_dictText',
          ellipsis: true,
          width: 153
        },
        {
          title: '业绩归属年度',
          align: 'center',
          dataIndex: 'year_dictText',
          ellipsis: true,
          width: 153
        },
        {
          title: '业主单位',
          align: 'center',
          dataIndex: 'ownerUnit_dictText',
          ellipsis: true,
          width: 153
        },
        {
          title: '项目来源',
          align: 'center',
          dataIndex: 'projectSource_dictText',
          ellipsis: true,
          width: 153
        },
        {
          title: '预计合同额（元）',
          align: 'center',
          dataIndex: 'estimatedContractAmount',
          ellipsis: true,
          width: 153
        },
        {
          title: '流程状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          ellipsis: true,
          width: 153
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      sourceData: [],
      stepStyle: {
        marginBottom: '60px',
        boxShadow: '0px -1px 0 0 #e8e8e8 inset'
      },
      treeList: [],
      proObject: {},
      dataSource1: [],
      dataSource2: [],
      dataSource3: [],
      prepareProjectApplyDataSource: [], // 申请记录预立项列表
      projectApplyDataSource: [], // 申请记录立项列表
      columns1: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          fixed: 'left',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '项目档案编号',
          align: 'center',
          dataIndex: 'finalNo'
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
          ellipsis: true
        },
        {
          title: '合同最新进度',
          align: 'center',
          dataIndex: 'contractNodeId_dictText',
          ellipsis: true
        },
        {
          title: '最近更新时间',
          align: 'center',
          dataIndex: 'contractLastOperTime'

        },
        {
          title: '完成状态',
          align: 'center',
          dataIndex: 'contractCompleteStatus_dictText'
        },
        {
          title: '编制状态',
          align: 'center',
          dataIndex: 'contractEditStatus_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      columns2: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          fixed: 'left',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '项目档案编号',
          align: 'center',
          dataIndex: 'finalNo'
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName'
        },
        {
          title: '合同总额（元）',
          align: 'center',
          dataIndex: 'contractTotalMoney'
        },
        {
          title: '应收款总额（元）',
          align: 'center',
          dataIndex: 'receivablesPaymentMoney'
        },
        {
          title: '实收款总额（元）',
          align: 'center',
          dataIndex: 'realCollectionPaymentMoney'
        },
        {
          title: '扣款总额（元）',
          align: 'center',
          dataIndex: 'deductMoney'
        },
        {
          title: '最近更新时间',
          align: 'center',
          dataIndex: 'lastPaymentTime'
        },
        {
          title: '编制状态',
          align: 'center',
          dataIndex: 'paymentEditStatus_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ]
    }
  },

  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          this.isDisableProjectNo = false
          return false
        }
        this.isDisableProjectNo = true
        return true
      }
      this.isDisableProjectNo = this.disabled
      return this.disabled
    },

    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    }
  },
  created() {
    this.model.applyType = '1'
    // 备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
    // 如果是流程中表单，则需要加载流程表单data
    this.showFlowData();
    // 加载数据字典信息
    this.initDictConfig();
    this.otherKey = 'taskProgressColumns'
    this.threeKey = 'projectApplyColumns'
	  this.customKey = 'columns'
  },
  mounted() {
    // 根据项目id获取树形进度
    this.getQueryTaskTreeById()
  },
  methods: {

    ...mapGetters(['userInfo']),
    handleViews(record, key) {
      this.$refs[key].edit(record)
      this.$refs[key].title = '查看'
      this.$refs[key].disableSubmit = true
    },
    translateDict() {
      if (this.proObject.productTeam) {
        return filterMultiDictText(this.dictOptions['productTeam'], this.proObject.productTeam + '')
      } else {
        return ''
      }
    },
    oneloadData() {
      this.dataSource1 = []
      const params = {
        projectId: this.$route.params.id,
        pageNo: 1,
        pageSize: 10000,
        column: '',
        order: ''
      }
      if (this.projectIdTo) {
        params.projectId = this.projectIdTo
      }
      getAction('/api/erp/progress/erpProgressContract/list', params).then(res => {
        if (res.success) {
          this.dataSource1 = res.result.records || []
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    twoloadData() {
      this.dataSource2 = []
      const params = {
        projectId: this.$route.params.id,
        pageNo: 1,
        pageSize: 10000,
        column: '',
        order: '',
        contractType: '1'
      }
      if (this.projectIdTo) {
        params.projectId = this.projectIdTo
      }
      getAction('/api/erp/progress/erpProgressPayment/list', params).then(res => {
        if (res.success) {
          this.dataSource2 = res.result.records || []
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    threeLoadData() {
      this.dataSource3 = []
      this.loading = true
      const params = {
        projectId: this.$route.params.id,
        pageNo: 1,
        pageSize: 10000,
        column: '',
        order: ''
      }
      if (this.projectIdTo) {
        params.projectId = this.projectIdTo
      }
      getAction('/api/erp/progress/erpProgressTask/progressList', params).then(res => {
        if (res.success) {
          this.dataSource3 = res.result.records || []
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.loading = false
      })
    },
    changeProjectTab (val) {
      if (val == '1') {
        this.getPrepareProjectApplyList()
      } else {
        this.getProjectApplyList()
      }
    },
    // 获取申请记录预立项列表
    getPrepareProjectApplyList() {
      this.prepareProjectApplyDataSource = []
      if (!this.model.prepareProjectId) {
        return
      }
      this.prepareProjectApplyLoading = true
      const params = {
        id: this.model.prepareProjectId,
        pageNo: 1,
        pageSize: -1,
        bpmStatus: '2,3',
        column: 'createTime',
        order: 'desc'
      }
      getAction('/api/erp/omc/prepareproject/erpOmcPrepareProject/all', params).then(res => {
        if (res.success) {
          this.prepareProjectApplyDataSource = res.result.records || []
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.prepareProjectApplyLoading = false
      })
    },
    // 获取申请记录预立项列表
    getProjectApplyList () {
      this.projectApplyDataSource = []
      this.projectApplyLoading = true

      let params = {
        bpmStatus: '2,3',
        column: 'bpmStatus,ifnull(updateTime,createTime)',
        order: 'desc'
      }
      let superQueryParams = [
        { field: 'projectNo', val: this.model.projectNo, rule: 'eq' },
        { field: 'finalProjectId', val: this.model.id, rule: 'eq' }
      ]
      if (superQueryParams) {
        params['superQueryParams'] = encodeURI(JSON.stringify(superQueryParams))
        params['superQueryMatchType'] = 'or'
      }
      getAction('/api/erp/omc/project/erpOmcProjectApply/all', params).then(res => {
        if (res.success) {
          this.projectApplyDataSource = res.result.records || []
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.projectApplyLoading = false
      })
    },
    onSelect(selectedKeys, info) {
      // 选择任务进度先隐藏，查到数据后显示
      this.taskShowType = false
      if (selectedKeys.length > 0) {
        this.getProQueryById(info.node._props.value)
        this.getQueryTaskNodeInfoById(info.node._props.label)
      }
    },
    handleChangeTab(key) {
      this.nodeList = []
      if (key == 1) {
        this.getQueryTaskTreeById()
      }
      if (key == 2) {
        this.getNodeTwo()
      }

      if (key == 3) {
        this.getNodeThree()
      }
    },
    getNodeThree() {
      let projectId = this.$route.params.id
      if (this.projectIdTo) {
        projectId = this.projectIdTo
      }
      getAction(this.url.PaymentNodeByProjectId, { id: projectId }).then((res) => {
        if (res.success) {
          this.nodeList = res.result || []
          this.onChange(0)
        }
      })
    },
    getNodeTwo() {
      let projectId = this.$route.params.id
      if (this.projectIdTo) {
        projectId = this.projectIdTo
      }
      getAction(this.url.queryListByProjectId, { id: projectId }).then((res) => {
        if (res.success) {
          this.nodeList = res.result || []
          this.onChange(0)
        }
      })
    },
    // 获取任务节点树状数据
    getQueryTaskTreeById() {
      let params = { id: this.$route.params.id };
      if (this.projectIdTo) {
        params.id = this.projectIdTo
      }
      getAction(this.url.queryTaskTreeById, params).then((res) => {
        if (res.success) {
          this.treeList = res.result || []
          if (this.treeList.length > 0) {
            this.getProQueryById(this.treeList[0].projectTaskId)
            this.getQueryTaskNodeInfoById(this.treeList[0].id)
          }
        }
      })
    },
    getProQueryById(id) {
      let params = { id: id };
      getAction(this.url.proQueryById, params).then((res) => {
        if (res.success) {
          this.proObject = res.result || {}
        }
      })
    },
    getQueryTaskNodeInfoById(id) {
      this.nodeList = []
      let params = { id: id };
      getAction(this.url.queryTaskNodeInfoById, params).then((res) => {
        if (res.success) {
          this.nodeList = res.result || []
          if (res.result.length > 0) {
            this.taskShowType = true
            this.onChange(0)
          }
        }
      })
    },
    // 任务进度的节点选择
    onChange(current) {
      this.modelTask = {}
      this.nodeList[current].isFill = '3';
      this.nodeList[current].choose = '1'
      for (var i = 0; i < this.nodeList.length; i++) {
        if (i != current) {
          this.nodeList[i].choose = '0'
        }
      }
      this.formTitle = this.nodeList[current].nodeName
      this.modelTask = this.nodeList[current]
      this.current = current;
      this.getNodeListText(this.nodeList[current].taskNodeId, current)
    },
    getNodeListText(ids, index) {
      var text = []; var fileList = []
      if (!ids) {
        return
      }
      let param = {
        taskNodeIds: ids
      }
      getAction(this.url.queryListByTaskByIds, param).then((res) => {
        if (res.success) {
          // this.selectedObj = res.result || []
          if (res.result) {
            res.result.forEach((item, index) => {
              text.push(item.nodeName)
              fileList.push(item.nodeFile)
            })
          }
          this.modelTask = Object.assign(this.modelDefault, this.nodeList[index]);
          this.modelTask.taskNodeText = text.toString()
          this.modelTask.nodeFile = fileList.toString()
          // this.$refs.inputModal.add(this.selectedObj, this.ids);
        }
      });
    },
    // 加载数据字典信息
    initDictConfig() {
      initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'productTeam', res.result)
        }
      })
      initDictOptions('erp_employee_file,name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'teamLeader', res.result)
        }
      })
      initDictOptions('progress_status').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'taskStatus', res.result)
        }
      })
    },
    // 业务分类新增
    handleAdd() {
      this.$refs.categoryList.add();
      this.$refs.categoryList.title = '新增';
      this.$refs.categoryList.disableSubmit = false;
    },
    // 业务分类编辑
    handleEdit(record) {
      this.$refs.categoryList.edit(record);
      this.$refs.categoryList.title = '修改';
      this.$refs.categoryList.disableSubmit = false;
    },
    // 业务分类删除
    handleDelete(id) {
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == id) {
          this.dataSource.splice(i, 1);
        }
      }
    },

    // 点击业务分类跳转详情
    handleDetail (record) {
      var that = this
      this.$nextTick(() => {
        getAction(this.url.taskById, { id: record.id }).then(res => {
          if (res.success) {
            const model = res.result
            that.$refs.taskReportForm.edit(model);
            that.$refs.taskReportForm.title = '任务档案';
          }
        })
      })
    },
    // 点击申请记录预立项跳转
    handlePrepareProjectDetail (record) {
      var that = this
      this.$nextTick(() => {
        const model = record
        that.$refs.prepareProjectReportForm.edit(model);
        that.$refs.prepareProjectReportForm.title = '预立项详情';
      })
    },
    // 点击申请记录立项跳转
    handleProjectDetail (record) {
      var that = this
      this.$nextTick(() => {
        const model = record
        that.$refs.projectReportForm.edit(model);
        that.$refs.projectReportForm.title = '立项详情';
      })
    },
    modalFormOk(data) {
      this.loading = true;
      let flag = true;
      // debugger;
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == data.id) {
          this.dataSource.splice(i, 1, data);
          flag = false;
        }
      }
      if (flag) {
        this.dataSource.push(data);
      }
      this.loading = false;
    },
    getProjectNo() {
      // debugger
      if (this.model.isPrepareEstablish == '0') {
        getAction(this.url.getProjectNo, {}).then((res) => {
          if (res.success) {
            let data = res.result.records || res.result
            // debugger;
            this.$set(this.model, 'projectNo', data)
            this.$set(this.modelDefault, 'projectNo', data)
          }
        })
      }
    },
    convertMoney() {
      let money = this.model.estimatedContractAmount
      this.$set(this.model, 'estimatedContractcapitalChineseAmount', convertCurrency(money))
    },
    contactsChange(val) {
      // debugger
      getAction('/api/erp/omc/customermanager/erpOmcCustomerManagerContact/queryById', { id: val }).then((res) => {
        if (res.success) {
          let data = res.result.records || res.result
          // debugger;
          // this.model.lxdh = data.lxfs;
          this.$set(this.model, 'contacts', val)
          this.$set(this.model, 'contactTel', data.lxfs)
        }
      })
    },
    ownerUnitChange() {
      this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
    },

    prepareProjectChange(e) {
      if (e) {
        let params = { id: e };
        getAction(this.url.queryPrepareProjectById, params).then((res) => {
          if (res.success) {
            if (res.result) {
              this.model.projectName = res.result.mc
              this.model.projectType = res.result.xmlx
              this.model.teamName = res.result.ywtd
              this.model.nowTeamName = res.result.ywtd
              this.model.undertaker = res.result.cjr

              this.model.isBidding = res.result.sfztb
              this.model.isEnvironmentalAssessmentProject = res.result.sfhpxm
              this.model.signUnit = res.result.qddw
              this.model.year = res.result.yjgsnd
              this.model.ownerUnit = res.result.yzdw

              this.model.contacts = res.result.lxr
              this.model.contactTel = res.result.lxdh
              this.model.areaCode = res.result.ssq
              this.model.projectSource = res.result.xmly

              this.model.estimatedContractAmount = res.result.yjhte
              this.model.estimatedContractcapitalChineseAmount = res.result.dx
              this.model.establishReason = res.result.lxsyjsm
              this.model.attachment = res.result.xgfj
              if (res.result.serviceList != null && res.result.serviceList.length > 0) {
                res.result.serviceList.forEach(item => {
                  let obj = {}
                  obj.id = item.id;
                  obj.categoryCode = item.serviceType
                  obj.categoryName = item.serviceName
                  this.dataSource.push(obj);
                });
              }
              // this.$refs.form.resetFields();
              this.model = Object.assign({}, this.model);
            }
          }
        });
      }
    },
    isPrepareEstablishChange(e) {
      if (e == '1') {
        this.isShowPrepareProject = true
      } else {
        this.isShowPrepareProject = false
        this.model.projectName = null;
        this.model.projectType = null;
        this.model.teamName = null;
        this.model.nowTeamName = null;
        this.model.undertaker = null;

        this.model.isBidding = null;
        this.model.isEnvironmentalAssessmentProject = null;
        this.model.signUnit = null;
        this.model.year = null;
        this.model.ownerUnit = null;

        this.model.contacts = null;
        this.model.contactTel = null;
        this.model.areaCode = null;
        this.model.projectSource = null;

        this.model.estimatedContractAmount = null;
        this.model.estimatedContractcapitalChineseAmount = null;
        this.model.establishReason = null;
        this.model.attachment = null;

        this.dataSource = null
      }
    },
    add() {
      this.getProjectNo();
      this.dataSource = []
      this.edit(this.modelDefault);
      this.userName = this.userInfo().empName;// 申请人名称
      this.model.proposer = this.userInfo().empId; // 申请人
      this.model.proposerDeptId = this.userInfo().departIds; // 申请部门
      this.model.createTime = moment().format('YYYY-MM-DD HH:mm');
    },
    edit(record) {
      this.isDisableProjectNo = true
      this.model = Object.assign({}, record);
      if (this.model.id) {
        this.$route.params.id = this.model.id
        this.getQueryTaskTreeById()
        // this.oneloadData()
        // this.twoloadData()
        this.threeLoadData()
        this.getPrepareProjectApplyList()
      }
      this.$set(this.model, 'nowTeamName', record.oldTeamId ? record.oldTeamId : record.teamName);
      getAction('/api/erp/omc/project/erpOmcProjectTask/listById', { id: this.model.id }).then((res) => {
        if (res.length > 0) {
          this.dataSource = res || res.result;
        }
      });
      this.visible = true;
    },
    // 根据项目查看投标信息
    loadDataByProjectId(val) {
      this.initDataSource()
      getAction(this.url.queryProjectById, { id: val }).then((res) => {
        if (res.success) {
          this.edit(res.result);
        }
      })
    },
    initDataSource() {
      this.dataSource = []
      this.dataSource1 = []
      this.dataSource2 = []
      this.treeList = []
      this.proObject = {}
      this.nodeList = []
      this.modelTask = {}
      this.taskShowType = false
    },
    // 渲染流程表单数据
    showFlowData() {
      if (this.formBpm === true) {
        let params = { id: this.formData.dataId };
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result);
          }
        });
      }
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          let list = this.dataSource;
          this.model.categoryList = list;
          this.model.teamName = this.model.nowTeamName
          this.$delete(this.model, 'nowTeamName')
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }
      })
    },
    htlxChange(item) {

    }
  }
}
</script>
<style scoped>
.task_title {
  font-family: 'Microsoft Tai Le';
  font-weight: 400;
  font-style: normal;
  font-size: 14px;
  color: #000000;
}

.task_info {
  font-family: 'Microsoft Tai Le';
  font-weight: 400;
  font-style: normal;
  font-size: 14px;
  color: #000000;
  margin-bottom: 20px;
  margin-top: 20px;
  white-space: normal;
  word-break: break-all;
  word-wrap: break-word;
}

.pro_node {
  font-weight: bold;
  font-size: 20px;
}
</style>
